package cloud.keveri.chat4j.provider.chatgpt.config;

import cloud.keveri.chat4j.provider.BaseProviderFactory;
import cloud.keveri.chat4j.provider.chatgpt.ChatgptBlender;

/**
 * Chatgpt 工厂
 * <p>
 * 作者：沈自在
 **/
public class ChatgptFactory implements BaseProviderFactory<ChatgptBlender, ChatgptConfig> {

    /**
     * Blender
     */
    private static ChatgptBlender chatgptBlender;

    /**
     * 工厂实例
     */
    private static final ChatgptFactory INSTANCE = new ChatgptFactory();

    private static final class ConfigHolder {
        private static ChatgptConfig config = ChatgptConfig.builder().build();
    }

    /**
     * 获取工厂实例
     */
    public static ChatgptFactory instance() {
        return INSTANCE;
    }

    @Override
    public ChatgptBlender createBlender(ChatgptConfig config) {
        if (null == chatgptBlender) {
            chatgptBlender = new ChatgptBlender(config);
        }
        return chatgptBlender;
    }

    @Override
    public ChatgptBlender refresh(ChatgptConfig config) {
        chatgptBlender = new ChatgptBlender(config);
        return chatgptBlender;
    }

    @Override
    public ChatgptConfig acquireConfig() {
        return ConfigHolder.config;
    }

    @Override
    public void setConfig(ChatgptConfig config) {
        ConfigHolder.config = config;
    }
}
